//
//  TestQuestionsReportViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/5/29.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "TestQuestionsReportViewController.h"
#import "HistoryOfTheSurveyViewController.h"
#import "EvaluationViewController.h"
#import "CommonUtil.h"
#import "myTabBarViewController.h"
#import "AppointmentViewController.h"

@interface TestQuestionsReportViewController (){
    
    int hig;
    NSMutableDictionary *mutableDictionary_allQuesitons;// all questions
    NSMutableDictionary *mutableDictionary_allQuesitonsTow;// all questions

}

@end

@implementation TestQuestionsReportViewController


- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    

    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    ////NSLog(@"%@youshiwo",self.dicID.allValues);
    
    

    
    
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        

    
    //设置导航栏头文字
    self.navigationItem.title = @"评测报告";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#44afd7" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _muArrau = [NSMutableArray array];
    _muArray = [NSMutableArray array];
    babyName = [NSMutableArray array];
    timeStamp = [NSMutableArray array];
    resultBrief = [NSMutableArray array];

    
    //自定义左右按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turntolast)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    
    

    if (self.picType) {
        
        [self otherView];
        
        
    } else {
        
        [self subView];
        UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]
                                     initWithTitle:@"测题"
                                     style:UIBarButtonItemStylePlain
                                     target:self
                                     action:@selector(btnClick)];
        [rightBtn setTintColor:[UIColor whiteColor]];
        self.navigationItem.rightBarButtonItem = rightBtn;

        
    }


    
    
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    ////NSLog(@"scrollViewWillBeginDragging");
}

-(void)btnClick{
    

    
    HistoryOfTheSurveyViewController * historyVC = [[HistoryOfTheSurveyViewController alloc]init];
    historyVC.dic = self.dic;
    historyVC.allkey = self.allkey;
    historyVC.allval = self.allval;
    [self.navigationController pushViewController:historyVC animated:YES];
    
    
    
    
    
}
-(void)turntolast{
    
    myTabBarViewController*tb = [[myTabBarViewController alloc]init];
    tb.selectedIndex = 1;
    [self  presentViewController:tb animated:YES completion:nil];

    
}

-(void)otherView{
    
    
    if ([self.picType integerValue] != 2) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 179+150+20-180+33+10, SCREEN_WIDTH, SCREEN_HEIGHT-179+150+20-180) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
        
    }

    
    NSDictionary *evaluationResultsDetails= @{@"taskId":self.taskId};
    [UserDAL evaluationResultsDetailsParams:evaluationResultsDetails withBlock:^(NSDictionary *data, NSError *error) {
        
        if (data) {
            ////NSLog(@"%@",data);
            
            NSArray *myArray = data[@"dataList"];

            
            if ([self.picType integerValue] == 2) {
                
                NSString * resultBriefs = [NSString stringWithFormat:@"%@",data[@"resultBrief"]];

                [_tableView removeFromSuperview];
                for (NSDictionary*myDic in myArray) {
                    
                    
                    NSString * name = [NSString stringWithFormat:@"%@",myDic[@"name"]];
                    NSString * point = [NSString stringWithFormat:@"%@",myDic[@"point"]];

                    [_muArrau addObject:name];
                    [_muArray addObject:point];
                    
                    
                }
                
                [MBProgressHUD hideHUDForView:self.view animated:YES];
                scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavbarHight, SCREEN_WIDTH, 200+NavbarHight)];
                
                scrollView.delegate = self;
                [scrollView flashScrollIndicators];
                scrollView.showsVerticalScrollIndicator = FALSE;
                scrollView.showsHorizontalScrollIndicator = FALSE;
                scrollView.contentSize = CGSizeMake(125/2+_muArrau.count*(20+20/2)+30, 200+NavbarHight);
                scrollView.directionalLockEnabled = YES;
                [self.view addSubview:scrollView];
                
                
                
                
                imageBale = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13, 125/2+_muArrau.count*(20+20/2), 170)];
                imageBale.image = [UIImage imageNamed:@"同城解读-付款页面线框@2x.png.png"];
                imageBale.layer.masksToBounds = YES; //没这句话它圆不起来
                imageBale.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                [scrollView addSubview:imageBale];
                
                                    UIImageView * imageBaled = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13+NavbarHight+25+170+NavbarHight, SCREEN_WIDTH-20, SCREEN_HEIGHT-170)];
                                    imageBaled.image = [UIImage imageNamed:@"老师介绍线框@2x.png.png"];
                                    imageBaled.layer.masksToBounds = YES; //没这句话它圆不起来
                                    imageBaled.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                                    [self.view addSubview:imageBaled];
                
                                    UIImageView * bieImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 13+NavbarHight+25+170-33/2+NavbarHight, 74/2, 33)];
                                    bieImageView.image = [UIImage imageNamed:@"别针@2x.png.png"];
                                    [self.view addSubview:bieImageView];
                //
                
                
                
                ////NSLog(@"str的数据为%lu,point的数据为",(unsigned long)_muArrau.count);
                
                
                for (int i = 0; i<_muArrau.count; i++) {
                    
                    
                    
                    NSString  * a = [_muArray objectAtIndex:i];
                    int b = [a integerValue];
                    
                    
                    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(125/2+(20+20/2)*i, 150-b+4, 20, b)];
                    image.backgroundColor = UIColorWithRGBA(255, 146, 147, 1);
                    image.layer.masksToBounds = YES; //没这句话它圆不起来
                    image.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                    
                    if (b == 0) {
                        
                        numLab = [[UILabel alloc]initWithFrame:CGRectMake(125/2+(20+20/2)*i, 150-b+4-10, 10, 10)];
                        numLab.text = [NSString stringWithFormat:@"%ld",(long)[[_muArray objectAtIndex:i] integerValue]];
                        numLab.adjustsFontSizeToFitWidth = YES;
                        numLab.font = [UIFont systemFontOfSize:10];
                        numLab.textAlignment = NSTextAlignmentCenter;
                        numLab.textColor = [UIColor blackColor];
                        ////NSLog(@"%@",[_muArray objectAtIndex:i]);
                        [scrollView addSubview:numLab];
                        
                    }else{
                        
                        numLab = [[UILabel alloc]initWithFrame:CGRectMake(0, -5, 20, 20)];
                        numLab.text = [NSString stringWithFormat:@"%ld",(long)[[_muArray objectAtIndex:i] integerValue]];
                        numLab.adjustsFontSizeToFitWidth = YES;
                        numLab.font = [UIFont systemFontOfSize:10];
                        numLab.textAlignment = NSTextAlignmentCenter;
                        numLab.textColor = [UIColor whiteColor];
                        ////NSLog(@"%@",[_muArray objectAtIndex:i]);
                        
                        [image addSubview:numLab];
                    }

                    
                    UIImageView * imageLine = [[UIImageView alloc]initWithFrame:CGRectMake(45, 25, 125/2+_muArray.count*(20+20/2)-40, 135)];
                    imageLine.image = [UIImage imageNamed:@"测评报告@2x.png"];
                    [scrollView addSubview:imageLine];
                    
                    
                    UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+13+15, 30, 20)];
                    lab.text = @"超常";
                    lab.textColor = UIColorWithRGBA(77, 93, 112, 1);
                    lab.font = [UIFont systemFontOfSize:9];
                    [scrollView addSubview:lab];
                    
                    UILabel * lab1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+20+5+22, 30, 20)];
                    lab1.text = @"优秀";
                    lab1.textColor = UIColorWithRGBA(77, 93, 112, 1);
                    lab1.font = [UIFont systemFontOfSize:9];
                    [scrollView addSubview:lab1];
                    
                    UILabel * lab2 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+40+10+18, 30, 20)];
                    lab2.text = @"中等";
                    lab2.textColor = UIColorWithRGBA(77, 93, 112, 1);
                    lab2.font = [UIFont systemFontOfSize:9];
                    [scrollView addSubview:lab2];
                    
                    UILabel * lab3 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+60+15+14, 30, 20)];
                    lab3.text = @"稍差";
                    lab3.textColor = UIColorWithRGBA(77, 93, 112, 1);
                    lab3.font = [UIFont systemFontOfSize:9];
                    [scrollView addSubview:lab3];
                    
                    
                    UILabel * lab4 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+80+20+10, 30, 20)];
                    lab4.text = @"迟缓";
                    lab4.textColor = UIColorWithRGBA(77, 93, 112, 1);
                    lab4.font = [UIFont systemFontOfSize:9];
                    [scrollView addSubview:lab4];
                    
                    
                    UILabel * lab5 = [[UILabel alloc]initWithFrame:CGRectMake(125/2+(20+20/2)*i-8, 160, 20+5+3+3, 20)];
                    lab5.text = [NSString stringWithFormat:@"%@",[_muArrau objectAtIndex:i]];
                    lab5.adjustsFontSizeToFitWidth = YES;
                    lab5.textColor =  UIColorWithRGBA(255, 146, 147, 1);
                    lab5.textAlignment = NSTextAlignmentCenter;
                    lab5.font = [UIFont systemFontOfSize:9];
                    [scrollView addSubview:lab5];
                    
                    
                    
                    [scrollView addSubview:image];

                    
                    
                }
                
                
                                    _oLab = [[UILabel alloc]initWithFrame:CGRectMake(0, NavbarHight+50+150+15+NavbarHight, SCREEN_WIDTH, 30)];
                                    _oLab.text = @" 评测报告";
                                    _oLab.font = [UIFont systemFontOfSize:19];
                                    _oLab.textAlignment = NSTextAlignmentCenter;
                                    // _oLab.backgroundColor = [UIColor redColor];
                                    [self.view addSubview:_oLab];
                
                                    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(20, NavbarHight+84+150+15+NavbarHight, SCREEN_WIDTH-40, 1)];
                                    lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
                                    [self.view addSubview:lineView];
                
                
                                    _tLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-10, NavbarHight+74+150+15+NavbarHight, SCREEN_WIDTH/2-10, 58)];
                                    _tLab.font = [UIFont systemFontOfSize:15];
                                    _tLab.textAlignment = NSTextAlignmentLeft;
                                    [self.view addSubview:_tLab];
                
                                    UILabel * timeLab = [[UILabel alloc]initWithFrame:CGRectMake(20, NavbarHight+74+150+15+NavbarHight, SCREEN_WIDTH/2, 58)];
                                    timeLab.font = [UIFont systemFontOfSize:15];
                                    timeLab.textAlignment = NSTextAlignmentLeft;
                                    [self.view addSubview:timeLab];
                
                
                ////NSLog(@"%@看看我是谁",resultBriefs);
                                    UILabel * titiLab = [[UILabel alloc]initWithFrame:CGRectMake(20, 179+150+25+NavbarHight, SCREEN_WIDTH-40, 58)];
                                    NSString * tstring =resultBriefs;
                
                                    titiLab.numberOfLines =0;
                                    UIFont * tfont = [UIFont systemFontOfSize:12];
                                    titiLab.font = tfont;
                                    titiLab.lineBreakMode =NSLineBreakByTruncatingTail ;
                                    titiLab.text = tstring ;
                                    [titiLab setBackgroundColor:[UIColor whiteColor]];
                                    [self.view addSubview:titiLab];
                
                                    CGSize size =CGSizeMake(SCREEN_WIDTH-30,MAXFLOAT);
                                    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
                                    CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
                                    titiLab.frame =CGRectMake(20,179+150+20+NavbarHight, actualsize.width, actualsize.height);
                                    [self.view addSubview:titiLab];
                
                
                
                UIButton * btnClick = [UIButton buttonWithType:UIButtonTypeCustom];
                btnClick.frame = CGRectMake(15, SCREEN_HEIGHT-80, SCREEN_WIDTH-30, 50);
                [btnClick setBackgroundImage:[UIImage imageNamed:@"gree@2x"] forState:UIControlStateNormal];
                [btnClick setBackgroundImage:[UIImage imageNamed:@"greeScl@2x"] forState:UIControlStateHighlighted];
                [btnClick setTitle:@"预约早教指导师" forState:UIControlStateNormal];
                [btnClick setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                btnClick.titleLabel.textAlignment = NSTextAlignmentCenter;
                [btnClick addTarget:self action:@selector(qulaoshi) forControlEvents:UIControlEventTouchUpInside];
                btnClick.userInteractionEnabled = YES;
                [self.view addSubview:btnClick];
                
                

                //柱状图
            } else {
                
                
                babyName = data[@"babyName"];
                timeStamp = data[@"timeStamp"];
                resultBrief = data[@"resultBrief"];
                
                
                for (NSDictionary*myDic in myArray) {
                    [_muArrau addObject:myDic[@"name"]];
                    [_muArray addObject:myDic[@"sugesstion"]];
                    
                    
//                    NSString * str = [NSString stringWithFormat:@"%@",myDic[@"name"]];
//                    NSString * sugesstion = [NSString stringWithFormat:@"%@",myDic[@"sugesstion"]];
                    
                    
                    
                    
                    
                }
                
                UIImageView * imageBaled = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13+NavbarHight+15, SCREEN_WIDTH-20, SCREEN_HEIGHT)];
                imageBaled.image = [UIImage imageNamed:@"老师介绍线框@2x.png.png"];
                imageBaled.layer.masksToBounds = YES; //没这句话它圆不起来
                imageBaled.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                [self.view addSubview:imageBaled];
                
                UIImageView * bieImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 13+NavbarHight, 74/2, 33)];
                bieImageView.image = [UIImage imageNamed:@"别针@2x.png.png"];
                [self.view addSubview:bieImageView];
                

                
                
                _oLab = [[UILabel alloc]initWithFrame:CGRectMake(0, NavbarHight+50+150+15-180, SCREEN_WIDTH, 30)];
                _oLab.text = [NSString stringWithFormat:@"%@评测报告",babyName];
                _oLab.adjustsFontSizeToFitWidth = YES;
                _oLab.font = [UIFont systemFontOfSize:19];
                _oLab.textAlignment = NSTextAlignmentCenter;
                // _oLab.backgroundColor = [UIColor redColor];
                [self.view addSubview:_oLab];
                
                UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(20, NavbarHight+84+150+15-180, SCREEN_WIDTH-40, 1)];
                lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
                [self.view addSubview:lineView];
                
                
                _tLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+10, NavbarHight+74+150+15-180, SCREEN_WIDTH/2+10, 58)];
                _tLab.text = [NSString stringWithFormat:@"日期：%@",timeStamp];
                _tLab.adjustsFontSizeToFitWidth = YES;
                _tLab.font = [UIFont systemFontOfSize:15];
                _tLab.textAlignment = NSTextAlignmentLeft;
                // _tLab.backgroundColor = [UIColor redColor];
                [self.view addSubview:_tLab];
                
                UILabel * timeLab = [[UILabel alloc]initWithFrame:CGRectMake(12, NavbarHight+74+150+15-180+38, SCREEN_WIDTH-24, 58)];
                timeLab.text = [NSString stringWithFormat:@"%@",resultBrief];
                timeLab.adjustsFontSizeToFitWidth = YES;
                timeLab.font = [UIFont systemFontOfSize:20];
                timeLab.textAlignment = NSTextAlignmentCenter;
                timeLab.textColor = [UIColor orangeColor];
                [self.view addSubview:timeLab];
                
                [self.view addSubview:_tableView];

                
                UIButton * btnClick = [UIButton buttonWithType:UIButtonTypeCustom];
                btnClick.frame = CGRectMake(15, SCREEN_HEIGHT-80, SCREEN_WIDTH-30, 50);
                [btnClick setBackgroundImage:[UIImage imageNamed:@"gree@2x"] forState:UIControlStateNormal];
                [btnClick setBackgroundImage:[UIImage imageNamed:@"greeScl@2x"] forState:UIControlStateHighlighted];
                [btnClick setTitle:@"预约早教指导师" forState:UIControlStateNormal];
                [btnClick setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                btnClick.titleLabel.textAlignment = NSTextAlignmentCenter;
                [btnClick addTarget:self action:@selector(qulaoshi) forControlEvents:UIControlEventTouchUpInside];
                btnClick.userInteractionEnabled = YES;
                [self.view addSubview:btnClick];
                
                

                
            }
            
            
            [MBProgressHUD hideHUDForView:_tableView animated:YES];
            
            [_tableView reloadData];

            
            
            
            
            
        }else{
            
            
            
            //如果没数据
            alert(@"暂无测题结果返回");
            
        }
        
        
        
        
        
        
        
    }];
    

    
    
    
    
    
    
    
}
-(void)qulaoshi{
    
    
    AppointmentViewController * AppointmentVC = [[AppointmentViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:AppointmentVC];
    [self  presentViewController:nav animated:YES completion:nil];
    

    
    
    
    
    
}



-(void)subView{
    
    
    
    
    
    
    if ([self.typeID integerValue] == 2)
    {
        
        
        
        
    }else{
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 179+150+20-180+33+10, SCREEN_WIDTH, SCREEN_HEIGHT-179+150+20-180) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
        [self.view addSubview:_tableView];
        
        
        
    }

    
    NSUserDefaults *userID = [NSUserDefaults standardUserDefaults];
    NSString *ID = [userID objectForKey:@"ID"];
    
    
    NSArray* arr = [self.dicID allValues];
    arr = [arr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
        NSComparisonResult result = [obj1 compare:obj2];
        return result==NSOrderedDescending;
    }];
    
    self.allkey = [NSMutableArray array];
    for(NSString* str in arr)
    {
        if ([str isEqualToString:@"0"]) {
            
            _name = @"可以";
            //NSLog(@"%@",_name);

        }else{
            
            _name = @"不可以";
            //NSLog(@"%@",_name);

        }
        
        [self.allkey addObject:_name];
        
        
    }
    
    //NSLog(@"%@",self.allkey);
    
    
    NSUserDefaults *task = [NSUserDefaults standardUserDefaults];
    NSString *taskNs = [task objectForKey:@"task"];
    
    NSDictionary *paras_ResultsSubmit = @{@"userId":ID,@"babyId":[BabyManager shareInstance].babyId,@"taskId":taskNs,@"results":[CommonUtil dictionaryToJson:self.dicID]};
    
    [UserDAL getevaluationResultsSubmitParams:paras_ResultsSubmit withBlock:^(NSDictionary *data, NSError *error) {
        
        
        if (data) {
            
            ////NSLog(@"dongcidaci");
            
            ////NSLog(@"data的数据为%@",data);
            
            NSArray *myArray = data[@"dataList"];
            if (myArray.count!=0) {
                
                
                if ([self.typeID integerValue] == 2) {
                    NSString * resultBriefs = [NSString stringWithFormat:@"%@",data[@"resultBrief"]];

                    for (NSDictionary*myDic in myArray) {
                        
                        
                        NSString * name = [NSString stringWithFormat:@"%@",myDic[@"name"]];
                        NSString * point = [NSString stringWithFormat:@"%@",myDic[@"point"]];
                        
                        [_muArrau addObject:name];
                        [_muArray addObject:point];
                        
                    }
                    
                    [MBProgressHUD hideHUDForView:self.view animated:YES];
                    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavbarHight, SCREEN_WIDTH, 200+NavbarHight)];
                    
                    scrollView.delegate = self;
                    [scrollView flashScrollIndicators];
                    scrollView.showsVerticalScrollIndicator = FALSE;
                    scrollView.showsHorizontalScrollIndicator = FALSE;
                    scrollView.contentSize = CGSizeMake(125/2+_muArrau.count*(20+20/2)+30, 200+NavbarHight);
                    scrollView.directionalLockEnabled = YES;
                    [self.view addSubview:scrollView];
                    
                    
                    
                    
                    imageBale = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13, 125/2+_muArrau.count*(20+20/2), 170)];
                    imageBale.image = [UIImage imageNamed:@"同城解读-付款页面线框@2x.png.png"];
                    imageBale.layer.masksToBounds = YES; //没这句话它圆不起来
                    imageBale.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                    [scrollView addSubview:imageBale];
                    
                    UIImageView * imageBaled = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13+NavbarHight+25+170+NavbarHight, SCREEN_WIDTH-20, SCREEN_HEIGHT-170)];
                    imageBaled.image = [UIImage imageNamed:@"老师介绍线框@2x.png.png"];
                    imageBaled.layer.masksToBounds = YES; //没这句话它圆不起来
                    imageBaled.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                    [self.view addSubview:imageBaled];
                    
                    UIImageView * bieImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 13+NavbarHight+25+170-33/2+NavbarHight, 74/2, 33)];
                    bieImageView.image = [UIImage imageNamed:@"别针@2x.png.png"];
                    [self.view addSubview:bieImageView];
                    //
                    
                    
                    
                    ////NSLog(@"str的数据为%lu,point的数据为",(unsigned long)_muArrau.count);
                    
                    
                    for (int i = 0; i<_muArrau.count; i++) {
                        
                        
                        
                        NSString  * a = [_muArray objectAtIndex:i];
                        int b = [a integerValue];
                        
                        UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(125/2+(20+20/2)*i, 150-b+4, 20, b)];
                        image.backgroundColor = UIColorWithRGBA(255, 146, 147, 1);
                        image.layer.masksToBounds = YES; //没这句话它圆不起来
                        image.layer.cornerRadius = 6.0; //设置图片圆角的尺度

                        if (b == 0) {
                            
                            numLab = [[UILabel alloc]initWithFrame:CGRectMake(125/2+(20+20/2)*i, 150-b+4-10, 10, 10)];
                            numLab.text = [NSString stringWithFormat:@"%ld",(long)[[_muArray objectAtIndex:i] integerValue]];
                            numLab.adjustsFontSizeToFitWidth = YES;
                            numLab.font = [UIFont systemFontOfSize:10];
                            numLab.textAlignment = NSTextAlignmentCenter;
                            numLab.textColor = [UIColor blackColor];
                            ////NSLog(@"%@",[_muArray objectAtIndex:i]);
                            [scrollView addSubview:numLab];

                            
                        }else{
                            
                            numLab = [[UILabel alloc]initWithFrame:CGRectMake(0, -5, 20, 20)];
                            numLab.text = [NSString stringWithFormat:@"%ld",(long)[[_muArray objectAtIndex:i] integerValue]];
                            numLab.adjustsFontSizeToFitWidth = YES;
                            numLab.font = [UIFont systemFontOfSize:10];
                            numLab.textAlignment = NSTextAlignmentCenter;
                            numLab.textColor = [UIColor whiteColor];
                            ////NSLog(@"%@",[_muArray objectAtIndex:i]);
                            [image addSubview:numLab];

                            
                        }
                        
                        
                        
                        
                        UIImageView * imageLine = [[UIImageView alloc]initWithFrame:CGRectMake(45, 25, 125/2+_muArray.count*(20+20/2)-40, 135)];
                        imageLine.image = [UIImage imageNamed:@"测评报告@2x.png"];
                        [scrollView addSubview:imageLine];
                        
                        
                        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+13+15, 30, 20)];
                        lab.text = @"超常";
                        lab.textColor = UIColorWithRGBA(77, 93, 112, 1);
                        lab.font = [UIFont systemFontOfSize:9];
                        [scrollView addSubview:lab];
                        
                        UILabel * lab1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+20+5+22, 30, 20)];
                        lab1.text = @"优秀";
                        lab1.textColor = UIColorWithRGBA(77, 93, 112, 1);
                        lab1.font = [UIFont systemFontOfSize:9];
                        [scrollView addSubview:lab1];
                        
                        UILabel * lab2 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+40+10+18, 30, 20)];
                        lab2.text = @"中等";
                        lab2.textColor = UIColorWithRGBA(77, 93, 112, 1);
                        lab2.font = [UIFont systemFontOfSize:9];
                        [scrollView addSubview:lab2];
                        
                        UILabel * lab3 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+60+15+14, 30, 20)];
                        lab3.text = @"稍差";
                        lab3.textColor = UIColorWithRGBA(77, 93, 112, 1);
                        lab3.font = [UIFont systemFontOfSize:9];
                        [scrollView addSubview:lab3];
                        
                        
                        UILabel * lab4 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20+80+20+10, 30, 20)];
                        lab4.text = @"迟缓";
                        lab4.textColor = UIColorWithRGBA(77, 93, 112, 1);
                        lab4.font = [UIFont systemFontOfSize:9];
                        [scrollView addSubview:lab4];
                        
                        
                        UILabel * lab5 = [[UILabel alloc]initWithFrame:CGRectMake(125/2+(20+20/2)*i-8, 160, 20+5+3+3, 20)];
                        lab5.text = [NSString stringWithFormat:@"%@",[_muArrau objectAtIndex:i]];
                        lab5.adjustsFontSizeToFitWidth = YES;
                        lab5.textColor =  UIColorWithRGBA(255, 146, 147, 1);
                        lab5.textAlignment = NSTextAlignmentCenter;
                        lab5.font = [UIFont systemFontOfSize:9];
                        [scrollView addSubview:lab5];
                        
                        
//                        [image addSubview:numLab];
                        [scrollView addSubview:image];
                        
                        
                        
                    }
                    
                    
                    _oLab = [[UILabel alloc]initWithFrame:CGRectMake(0, NavbarHight+50+150+15+NavbarHight, SCREEN_WIDTH, 30)];
                    _oLab.text = @" 评测报告";
                    _oLab.font = [UIFont systemFontOfSize:19];
                    _oLab.textAlignment = NSTextAlignmentCenter;
                    // _oLab.backgroundColor = [UIColor redColor];
                    [self.view addSubview:_oLab];
                    
                    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(20, NavbarHight+84+150+15+NavbarHight, SCREEN_WIDTH-40, 1)];
                    lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
                    [self.view addSubview:lineView];
                    
                    
                    _tLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-10, NavbarHight+74+150+15+NavbarHight, SCREEN_WIDTH/2-10, 58)];
                    //                    _tLab.text = @"评测日期:2015-03-06（空)";
                    _tLab.font = [UIFont systemFontOfSize:15];
                    _tLab.textAlignment = NSTextAlignmentLeft;
                    // _tLab.backgroundColor = [UIColor redColor];
                    [self.view addSubview:_tLab];
                    
                    UILabel * timeLab = [[UILabel alloc]initWithFrame:CGRectMake(20, NavbarHight+74+150+15+NavbarHight, SCREEN_WIDTH/2, 58)];
                    //                    timeLab.text = @"一年5个月（空）";
                    timeLab.font = [UIFont systemFontOfSize:15];
                    timeLab.textAlignment = NSTextAlignmentLeft;
                    // _tLab.backgroundColor = [UIColor redColor];
                    [self.view addSubview:timeLab];
                    
                    
                    ////NSLog(@"%@看看我是谁",resultBriefs);
                    UILabel * titiLab = [[UILabel alloc]initWithFrame:CGRectMake(20, 179+150+25+NavbarHight, SCREEN_WIDTH-40, 58)];
                    NSString * tstring =resultBriefs;
                    
                    titiLab.numberOfLines =0;
                    UIFont * tfont = [UIFont systemFontOfSize:12];
                    titiLab.font = tfont;
                    titiLab.lineBreakMode =NSLineBreakByTruncatingTail ;
                    titiLab.text = tstring ;
                    [titiLab setBackgroundColor:[UIColor whiteColor]];
                    [self.view addSubview:titiLab];
                    
                    CGSize size =CGSizeMake(SCREEN_WIDTH-30,MAXFLOAT);
                    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
                    CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
                    titiLab.frame =CGRectMake(20,179+150+20+NavbarHight, actualsize.width, actualsize.height);
                    [self.view addSubview:titiLab];

                    
                    
                    
                    
                } else {
                    
                    
                    babyName = data[@"babyName"];
                    timeStamp = data[@"timeStamp"];
                    resultBrief = data[@"resultBrief"];
                    
                    
                    for (NSDictionary*myDic in myArray) {
                        [_muArrau addObject:myDic[@"name"]];
                        [_muArray addObject:myDic[@"sugesstion"]];
                        
                        
//                        NSString * str = [NSString stringWithFormat:@"%@",myDic[@"name"]];
//                        NSString * sugesstion = [NSString stringWithFormat:@"%@",myDic[@"sugesstion"]];
                        
                        
                        
                    }
                    
                    UIImageView * imageBaled = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13+NavbarHight+15, SCREEN_WIDTH-20, SCREEN_HEIGHT)];
                    imageBaled.image = [UIImage imageNamed:@"老师介绍线框@2x.png.png"];
                    imageBaled.layer.masksToBounds = YES; //没这句话它圆不起来
                    imageBaled.layer.cornerRadius = 6.0; //设置图片圆角的尺度
                    [self.view addSubview:imageBaled];
                    
                    UIImageView * bieImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 13+NavbarHight, 74/2, 33)];
                    bieImageView.image = [UIImage imageNamed:@"别针@2x.png.png"];
                    [self.view addSubview:bieImageView];
                    
                    
                    
                    
                    _oLab = [[UILabel alloc]initWithFrame:CGRectMake(0, NavbarHight+50+150+15-180, SCREEN_WIDTH, 30)];
                    _oLab.text = [NSString stringWithFormat:@"%@评测报告",babyName];
                    _oLab.adjustsFontSizeToFitWidth = YES;
                    _oLab.font = [UIFont systemFontOfSize:19];
                    _oLab.textAlignment = NSTextAlignmentCenter;
                    [self.view addSubview:_oLab];
                    
                    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(20, NavbarHight+84+150+15-180, SCREEN_WIDTH-40, 1)];
                    lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
                    [self.view addSubview:lineView];
                    
                    
                    _tLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+10, NavbarHight+74+150+15-180, SCREEN_WIDTH/2+10, 58)];
                    _tLab.text = [NSString stringWithFormat:@"日期：%@",timeStamp];
                    _tLab.adjustsFontSizeToFitWidth = YES;
                    _tLab.font = [UIFont systemFontOfSize:15];
                    _tLab.textAlignment = NSTextAlignmentLeft;
                    [self.view addSubview:_tLab];
                    
                    UILabel * timeLab = [[UILabel alloc]initWithFrame:CGRectMake(12, NavbarHight+74+150+15-180+38, SCREEN_WIDTH-24, 58)];
                    timeLab.text = [NSString stringWithFormat:@"%@",resultBrief];
                    timeLab.adjustsFontSizeToFitWidth = YES;
                    timeLab.font = [UIFont systemFontOfSize:20];
                    timeLab.textAlignment = NSTextAlignmentCenter;
                    timeLab.textColor = [UIColor orangeColor];
                    [self.view addSubview:timeLab];
                    
                    [self.view addSubview:_tableView];
                    
                    
                    
                    
                    
                    
                }
                [MBProgressHUD hideHUDForView:_tableView animated:YES];

                [_tableView reloadData];

            }else{
                
                alert(@"暂无测题结果返回");
                
            }
            
            
        } else {
            
            
            
        }
        
        
    }];

    
    
    
    
}


#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _muArrau.count;
    
}

#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    for (int i = 0; i<_muArrau.count; i++) {
        
        if (indexPath.row == i) {

            UILabel * titiLab = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-40, 58)];
            NSString * tstring =[NSString stringWithFormat:@"%@：%@",_muArrau[indexPath.row],_muArray[indexPath.row]];
            
            titiLab.numberOfLines =0;
            UIFont * tfont = [UIFont systemFontOfSize:12];
            titiLab.font = tfont;
            titiLab.lineBreakMode =NSLineBreakByTruncatingTail ;
            titiLab.text = tstring ;
            [titiLab setBackgroundColor:[UIColor whiteColor]];
            
            CGSize size =CGSizeMake(SCREEN_WIDTH-30,MAXFLOAT);
            NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
            CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
            titiLab.frame =CGRectMake(20,5, actualsize.width, actualsize.height);
            
            
            return  actualsize.height+10;

            
            
    
        }
    
    
    }
    
    return 10;
}
#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    static NSString *ID = @"Cell";
    //    CheckBoxTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];//以indexPath来唯一确定cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        
        
        //        ////NSLog(@"题目:%@",mutableDictionary_allQuesitons.allValues);
        
        
    }
    ////NSLog(@"%@dededededededede",timeStamp);
    
    
    
    
    
    
    UILabel * titiLab = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-40, 58)];
    NSString * tstring =[NSString stringWithFormat:@"%@：%@",_muArrau[indexPath.row],_muArray[indexPath.row]];
    
    titiLab.numberOfLines =0;
    UIFont * tfont = [UIFont systemFontOfSize:12];
    titiLab.font = tfont;
    titiLab.lineBreakMode =NSLineBreakByTruncatingTail ;
    titiLab.text = tstring ;
    [titiLab setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:titiLab];
    
    CGSize size =CGSizeMake(SCREEN_WIDTH-30,MAXFLOAT);
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
    CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
    titiLab.frame =CGRectMake(20,5, actualsize.width, actualsize.height);
    [cell addSubview:titiLab];
    

    _tableView.rowHeight = actualsize.height+10;
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 1, _tableView.rowHeight)];
    lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
    [cell addSubview:lineView];

    UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-11, 0, 1, _tableView.rowHeight)];
    lineView1.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
    [cell addSubview:lineView1];
    
    if (indexPath.row == _muArray.count-1) {
        
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(10, _tableView.rowHeight-1, SCREEN_WIDTH-20, 1)];
        lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
        [cell addSubview:lineView];
        
    }
    
    
    
    return cell;
    
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    NSString *msg = [[NSString alloc] initWithFormat:@"您点击的是第%d个按钮!",buttonIndex];
    ////NSLog(@"msg:%@",msg);
    if (buttonIndex == 0) {
        
        myTabBarViewController*tb = [[myTabBarViewController alloc]init];
        tb.selectedIndex = 1;
        [self  presentViewController:tb animated:YES completion:nil];

        ////NSLog(@"1111111");
        
    }else if(buttonIndex == 1){
        
        
        ////NSLog(@"2222222");
        
        
    }
    
    
}


#pragma mark--- tableViewDelegate 有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}
#pragma mark--- tableViewDelegat 点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
